﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using vensoft.Entities;
using vensoft.BussinesLogic;

namespace vensoft.Win32
{
    public partial class frmMostrarHistoricoAB : Form
    {
        IHistoricoABBL historicoABBL;

        public frmMostrarHistoricoAB()
        {
            InitializeComponent();
            historicoABBL = new HistoricoABBL();
        }

        private void frmMostrarHistoricoAB_Load(object sender, EventArgs e)
        {
            rdbFechas.Checked = true;
            txtCodigoProducto.Visible = false;
            lblCod_Prod.Visible = false;
            historicoABBindingSource.DataSource = historicoABBL.GetAllFromHistoricoAB();
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnMostrarTodo_Click(object sender, EventArgs e)
        {
            historicoABBindingSource.DataSource = historicoABBL.GetAllFromHistoricoAB();
        }

        private void btnBuscarHistoricoAB_Click(object sender, EventArgs e)
        {
            if (rdbFechas.Checked == true)
            {
                historicoABBindingSource.DataSource = historicoABBL.GetAllFromHistoricoABByFechas((Convert.ToDateTime(dtpDesde.Value.ToString())).AddDays(-1), (Convert.ToDateTime(dtpHasta.Value.ToString())));
            }
            else if (rdbCodigo.Checked == true)
            {
                historicoABBindingSource.DataSource = historicoABBL.GetAllFromHistoricoABByCodProd(txtCodigoProducto.Text);  
            }
        }

        private void rdbCodigo_CheckedChanged(object sender, EventArgs e)
        {
            if (rdbCodigo.Checked == true)
            {
                dtpDesde.Visible = false;
                dtpHasta.Visible = false;
                lblDesde.Visible = false;
                lblHasta.Visible = false;
                lblCod_Prod.Visible = true;
                txtCodigoProducto.Visible = true;
            }
            else if (rdbFechas.Checked == true)
            {
                dtpDesde.Visible = true;
                dtpHasta.Visible = true;
                lblDesde.Visible = true;
                lblHasta.Visible = true;
                lblCod_Prod.Visible = false;
                txtCodigoProducto.Visible = false;
            }
        }
    }
}
